// C++ 17常用新特性(十一)-- - 折叠表达式

#include <iostream>

using namespace std;

// C++11 的实现
//// {{
template <typename T = int>
constexpr auto Sum() {
  return T(0);
}

template <typename T, typename... Ts>
constexpr auto Sum(T arg, Ts... args) {
  return arg + Sum(args...);
}

template <typename T>
constexpr auto SumB(T arg) {
  return arg;
}

template <typename T1, typename... Ts>
constexpr auto SumB(T1 arg1, Ts... otherArgs) {
  return arg1 + SumB(otherArgs...);
}
//// }}

// C++17 使用初始值为 0 的左折叠表达式
template <typename... T>
auto Sum17(T... args) {
  return (0 + ... + args);
}

int main() {
  cout << Sum() << endl;
  cout << Sum(1, 3.5, 4) << endl;
  cout << Sum(1.0, 3.5, 4) << endl;
  cout << "----------------------------\n";
  cout << SumB(1, 3.5, 4) << endl;
  cout << SumB(1.0, 3.5, 4) << endl;
  cout << "----------------------------\n";
  cout << Sum17() << endl;
  cout << Sum17(1, 3.5, 4) << endl;
  return 0;
}